﻿using ManhattanControl.model;
using Newtonsoft.Json;
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace ManhattanControl
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        public static Socket serverSocket;
        public static Socket CoffeeSocket;
        public static Socket IceSocket;
        public static Socket DPSocket;
        private static byte[] result = new byte[9216];
        private static int myProt = 8885;  //端口 
        public static bool ismake = false;
        public static bool isCoffeeRobot = false;
        public static bool isIceRobot = false;
        public static string IPorPortUrl = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"IPorPortMessage.txt";
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!File.Exists(IPorPortUrl))
                {
                    using (FileStream stream = File.Create(IPorPortUrl))
                    {
                        stream.Close();
                        stream.Dispose();
                        IPorPortInfo porPortInfo1 = IPorPortInfo.Instance;
                        File.WriteAllText(IPorPortUrl, JsonConvert.SerializeObject(porPortInfo1));
                    }
                }
                else
                {
                    var dd = File.ReadAllText(IPorPortUrl);
                    var porPortInfo = JsonConvert.DeserializeObject<IPorPortInfo>(File.ReadAllText(IPorPortUrl));
                    IPorPortInfo.Instance.CoffeeIP = porPortInfo.CoffeeIP;
                    IPorPortInfo.Instance.CoffeePort = porPortInfo.CoffeePort;
                    IPorPortInfo.Instance.RobotIPLeft = porPortInfo.RobotIPLeft;
                    IPorPortInfo.Instance.RobotIPRight = porPortInfo.RobotIPRight;
                    IPorPortInfo.Instance.PortName = porPortInfo.PortName;
                    IPorPortInfo.Instance.PortNameR = porPortInfo.PortNameR;
                    IPorPortInfo.Instance.PrinterCoffeeIP = porPortInfo.PrinterCoffeeIP;
                    IPorPortInfo.Instance.PrinterCofferPort = porPortInfo.PrinterCofferPort;
                    IPorPortInfo.Instance.EWMPortName = porPortInfo.EWMPortName;
                    IPorPortInfo.Instance.ZBPortName = porPortInfo.ZBPortName;
                    IPorPortInfo.Instance.CoffeePortName = porPortInfo.CoffeePortName;
                    IPorPortInfo.Instance.SugarInit1 = porPortInfo.SugarInit1;
                    IPorPortInfo.Instance.SugarInit2 = porPortInfo.SugarInit2;
                    IPorPortInfo.Instance.SugarInit3 = porPortInfo.SugarInit3;
                }
                saveDeviceMatter save = new saveDeviceMatter();
                save.matterStatusJson = JsonConvert.SerializeObject(CoffeeMatters.Instance);
                save.deviceStatusJson = JsonConvert.SerializeObject(deviceStatus.Instance);
                var saves = JsonConvert.SerializeObject(save);
                HttpMsg.Instance.saveDeviceMatterMsg(saves);
                CoffeeMake();
            }
            catch (Exception)
            {
                return;
            }
        }
        public void CoffeeSend(string name, string tag)
        {
            try
            {
                if (CoffeeSocket != null)
                {
                    if (isCoffeeRobot)
                    {
                        ClientList clientList = new ClientList();
                        MessageClientList coffeelist = MessageClientList.Instance;
                        coffeelist.Name = name;
                        coffeelist.type = double.TryParse(tag, out double do1) ? do1 : 0;
                        clientList.message = coffeelist;
                        clientList.code = 0;
                        CoffeeSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
                    }
                    else
                    {
                        MessageBox.Show("Please update later, the program is loading!");
                    }
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        public void IceSend(string name, string tag)
        {
            try
            {
                if (IceSocket != null)
                {
                    if (isIceRobot)
                    {
                        ClientList clientList = new ClientList();
                        MessageClientList coffeelist = MessageClientList.Instance;
                        coffeelist.Name = name;
                        coffeelist.type = double.TryParse(tag, out double do1) ? do1 : 0;
                        clientList.message = coffeelist;
                        clientList.code = 0;
                        IceSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
                    }
                    else
                    {
                        MessageBox.Show("Please update later, the program is loading!");
                    }
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        #region 服务器链接
        /// <summary>
        /// 服务器启动监听各种信息动态
        /// </summary>
        public void CoffeeMake()
        {
            try
            {
                //string LocalIP = "192.168.41.7";
                //var host = Dns.GetHostEntry(Dns.GetHostName());
                //foreach (var ips in host.AddressList)
                //{
                //    if (ips.AddressFamily == AddressFamily.InterNetwork)
                //    {
                //        LocalIP = ips.ToString();
                //        // Console.WriteLine"IP Address = " + (ips.ToString());
                //    }
                //}
                //服务器IP地址 
                IPAddress ip = IPAddress.Parse(IPorPortInfo.Instance.CoffeeIP);
                serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                serverSocket.Bind(new IPEndPoint(ip, myProt)); //绑定IP地址：端口 
                serverSocket.Listen(10);  //设定最多10个排队连接请求 
                Console.WriteLine("启动监听{0}成功", serverSocket.LocalEndPoint.ToString());
                //通过Clientsoket发送数据 
                Thread myThread = new Thread(ListenClientConnect);
                myThread.IsBackground = true;
                myThread.Start();
                foreach (System.Diagnostics.Process thisProc in System.Diagnostics.Process.GetProcesses())
                {
                    if (thisProc.ProcessName == "NewZealandCoffee")
                    {
                        if (!thisProc.CloseMainWindow())
                            thisProc.Kill(); //当发送关闭窗口命令无效时强行结束进程     
                    }
                    if (thisProc.ProcessName == "DuBaiCoffee2")
                    {
                        if (!thisProc.CloseMainWindow())
                            thisProc.Kill(); //当发送关闭窗口命令无效时强行结束进程     
                    }
                    if (thisProc.ProcessName == "MINIGKP")
                    {
                        if (!thisProc.CloseMainWindow())
                            thisProc.Kill(); //当发送关闭窗口命令无效时强行结束进程     
                    }
                }
                Process ps = new Process();
                string yourURL = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"ice";
                ps.StartInfo.FileName = "NewZealandCoffee.exe";
                ps.StartInfo.WorkingDirectory = yourURL;
                ps.Start();

                Thread.Sleep(1000);
                Process ps2 = new Process();
                string yourURL2 = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"coffee";
                ps2.StartInfo.FileName = "DuBaiCoffee2.exe";
                ps2.StartInfo.WorkingDirectory = yourURL2;
                ps2.Start();

                Thread.Sleep(1000);
                Process ps1 = new Process();
                string yourURL1 = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"显示屏";
                ps1.StartInfo.FileName = "MINIGKP.exe";
                ps1.StartInfo.WorkingDirectory = yourURL1;
                ps1.Start();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                serverSocket.Shutdown(SocketShutdown.Both);
                serverSocket.Close();
                CoffeeMake();
                return;
            }
        }
        /// <summary> 
        /// 监听客户端连接 
        /// </summary> 
        private void ListenClientConnect()
        {
            try
            {
                while (true)
                {
                    Socket clientSocket = serverSocket.Accept();
                    string ip = ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString();
                    Console.WriteLine("点单");
                    Thread receiveThread = new Thread(ReceiveMessage);
                    receiveThread.IsBackground = true;
                    receiveThread.Start(clientSocket);
                    Thread.Sleep(10);
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary> 
        /// 接收消息 
        /// </summary> 
        /// <param name="clientSocket"></param> 
        private void ReceiveMessage(object clientSockets)
        {
            Socket myClientSocket = (Socket)clientSockets;

            while (true)
            {
                try
                {
                    //通过clientSocket接收数据 
                    int receiveNumber = myClientSocket.Receive(result);
                    if (receiveNumber == 0) continue;
                    try
                    {
                        var msg = Encoding.UTF8.GetString(result, 0, receiveNumber);
                        if (msg.Trim().Length != 0)
                        {
                            var making = JsonConvert.DeserializeObject<ClientList>(msg);
                            if (making != null)
                            {
                                if (making.code == 4)
                                {
                                    CoffeeSocket = myClientSocket;
                                }
                                else if (making.code == 5)
                                {
                                    IceSocket = myClientSocket;
                                }
                                else if (making.code == 1)
                                {
                                    IceMsg(making.MsgIceBol);
                                }
                                else if (making.code == 2)
                                {
                                    CoffeeMsg(making.MsgBol);
                                }
                                else if (making.code == 3)
                                {
                                    if (making.message.Name == "Reload_L")
                                    {
                                        RobotSel_L(making.robotMsg);
                                    }
                                    else if (making.message.Name == "Reload_R")
                                    {
                                        RobotSel_R(making.robotMsg);
                                    }
                                    else if (making.message.Name == "Reload_I")
                                    {
                                        RobotSel_LN(making.robotMsg);
                                    }
                                }
                                else if (making.code == 0)
                                {
                                    DOSelect(making.message.Name, making.message.type);
                                }
                                else if (making.code == 11)
                                {
                                    DPSocket = myClientSocket;
                                    if (DPSocket != null)
                                    {
                                        Thread.Sleep(1000);
                                        ClientList clientList = new ClientList();
                                        MessageClientList coffeelist = MessageClientList.Instance;
                                        clientList.message = coffeelist;
                                        clientList.IsMake = ismake;
                                        DPSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
                                    }
                                }
                                else if (making.code == 10)
                                {
                                    if (DPSocket != null)
                                    {
                                        Thread.Sleep(1000);
                                        ClientList clientList = new ClientList();
                                        MessageClientList coffeelist = MessageClientList.Instance;
                                        clientList.message = coffeelist;
                                        clientList.IsMake = making.IsMake;
                                        DPSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
                                        ismake = making.IsMake;
                                    }
                                }
                                else if (making.code == 12)
                                {
                                    isCoffeeRobot = true;
                                }
                                else if (making.code == 13)
                                {
                                    isIceRobot = true;
                                }
                            }
                        }
                        Thread.Sleep(10);
                    }
                    catch (Exception)
                    {
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    break;
                }
            }

        }
        public void CoffeeMsg(WuLiaoCoffeeSel wuLiaoCoffee)
        {
            try
            {

                CoffeeMatters.Instance.CoffeeMatter1 = wuLiaoCoffee.CupFeed1_Sel_Bol ? 1 : 0;
                if (CoffeeMatters.Instance.CoffeeMatter2 != (wuLiaoCoffee.CoffeeBean_Sel_Bol ? 1 : 0))
                    wuLiaoCoffee.IsWLBol = true;
                CoffeeMatters.Instance.CoffeeMatter2 = wuLiaoCoffee.CoffeeBean_Sel_Bol ? 1 : 0;
                CoffeeMatters.Instance.CoffeeMatter3 = wuLiaoCoffee.Milk_Sel_Bol ? 1 : 0;
                if (CoffeeMatters.Instance.CoffeeMatter4 != (wuLiaoCoffee.Ice_Bol ? 1 : 0))
                    wuLiaoCoffee.IsWLBol = true;
                CoffeeMatters.Instance.CoffeeMatter4 = wuLiaoCoffee.Ice_Bol ? 1 : 0;
                CoffeeMatters.Instance.CoffeeMatter5 = wuLiaoCoffee.Water_Sel_Bol ? 1 : 0;
                //CoffeeMatters.Instance.CoffeeMatter6 = wuLiaoCoffee.GT1_Sel_Bol ? 1 : 0;
                //CoffeeMatters.Instance.CoffeeMatter7 = wuLiaoCoffee.GT2_Sel_Bol ? 1 : 0;
                //CoffeeMatters.Instance.CoffeeMatter8 = wuLiaoCoffee.GT3_Sel_Bol ? 1 : 0;
                if (CoffeeMatters.Instance.CoffeeMatter9 != (wuLiaoCoffee.Print_Bol ? 1 : 0))
                    wuLiaoCoffee.IsWLBol = true;
                CoffeeMatters.Instance.CoffeeMatter9 = wuLiaoCoffee.Print_Bol ? 1 : 0;
                if (CoffeeMatters.Instance.CoffeeMatter10 != (wuLiaoCoffee.IceCup1_Bol || wuLiaoCoffee.IceCup2_Bol ? 1 : 0))
                    wuLiaoCoffee.IsWLBol = true;
                CoffeeMatters.Instance.CoffeeMatter10 = wuLiaoCoffee.IceCup1_Bol || wuLiaoCoffee.IceCup2_Bol ? 1 : 0;
                if (CoffeeMatters.Instance.CoffeeMatter11 != (wuLiaoCoffee.CoffeeWarn ? 1 : 0))
                    wuLiaoCoffee.IsWLBol = true;
                CoffeeMatters.Instance.CoffeeMatter11 = wuLiaoCoffee.CoffeeWarn ? 1 : 0;
                if (CoffeeMatters.Instance.CoffeeMatter12 != (wuLiaoCoffee.RobotWarn ? 1 : 0))
                    wuLiaoCoffee.IsWLBol = true;
                CoffeeMatters.Instance.CoffeeMatter12 = wuLiaoCoffee.RobotWarn ? 1 : 0;
                CoffeeMatters.Instance.CoffeeMatter16 = wuLiaoCoffee.Water3_Sel_Bol ? 1 : 0;
                // CoffeeMatters.Instance.CoffeeMatter13 = wuLiaoCoffee.CoffeeBean2_Sel_Bol ? 1 : 0;
                this.Dispatcher.BeginInvoke(new Action(delegate
                {
                    AQGS_B.Background = wuLiaoCoffee.BANNER_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    AQGS_F.Foreground = wuLiaoCoffee.BANNER_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    CCMSDW_B.Background = wuLiaoCoffee.PushRodUP_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    CCMSDW_F.Foreground = wuLiaoCoffee.PushRodUP_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    CCMXDW_B.Background = wuLiaoCoffee.PushRodDown_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    CCMXDW_F.Foreground = wuLiaoCoffee.PushRodDown_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    CCJC_B.Background = wuLiaoCoffee.OutMealCup_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    CCJC_F.Foreground = wuLiaoCoffee.OutMealCup_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    BJC8_B.Background = wuLiaoCoffee.CupFeed1_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    BJC8_F.Foreground = wuLiaoCoffee.CupFeed1_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    IceCup1_B.Background = wuLiaoCoffee.IceCup1_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    IceCup1_F.Foreground = wuLiaoCoffee.IceCup1_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    IceCup2_B.Background = wuLiaoCoffee.IceCup2_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    IceCup2_F.Foreground = wuLiaoCoffee.IceCup2_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    //CFJJC_B.Background = wuLiaoCoffee.CupFeed2_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    //CFJJC_F.Foreground = wuLiaoCoffee.CupFeed2_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    JBCGJC_B.Background = wuLiaoCoffee.TakeCup_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    JBCGJC_F.Foreground = wuLiaoCoffee.TakeCup_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    BFK8_B.Background = wuLiaoCoffee.LBQFK1_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    BFK8_F.Foreground = wuLiaoCoffee.LBQFK1_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    //BFK8_B.Background = wuLiaoCoffee.LBQFK2_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    //BFK8_F.Foreground = wuLiaoCoffee.LBQFK2_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    MILK_B.Background = wuLiaoCoffee.Milk_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    MILK_F.Foreground = wuLiaoCoffee.Milk_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    WATER_B.Background = wuLiaoCoffee.Water_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    WATER_F.Foreground = wuLiaoCoffee.Water_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    IceWater_B.Background = wuLiaoCoffee.Water2_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    IceWater_F.Foreground = wuLiaoCoffee.Water2_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    LHWater_B.Background = wuLiaoCoffee.Water3_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    LHWater_F.Foreground = wuLiaoCoffee.Water3_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    DYJJC_B.Background = wuLiaoCoffee.Print_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    DYJJC_F.Foreground = wuLiaoCoffee.Print_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    CFJJC_B.Background = wuLiaoCoffee.CoffeeWarn ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    CFJJC_F.Foreground = wuLiaoCoffee.CoffeeWarn ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    JQRJC_B.Background = wuLiaoCoffee.RobotWarn ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    JQRJC_F.Foreground = wuLiaoCoffee.RobotWarn ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    ZBJJC_B.Background = wuLiaoCoffee.Ice_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    ZBJJC_F.Foreground = wuLiaoCoffee.Ice_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    //TTime1.Text = wuLiaoCoffee.SugarInit1.ToString();
                    //TTime2.Text = wuLiaoCoffee.SugarInit2.ToString();
                    //TTime3.Text = wuLiaoCoffee.SugarInit3.ToString();
                    //STime1.Text = wuLiaoCoffee.GSInit1.ToString();
                    //STime2.Text = wuLiaoCoffee.GSInit2.ToString();
                    //BSTime1.Text = wuLiaoCoffee.BSInit1.ToString();
                }));
                if (wuLiaoCoffee.IsWLBol)
                {
                    TestDelegateInvoke testDelegate = new TestDelegateInvoke(DelegateInvokeMethod);
                    testDelegate.BeginInvoke(null, null);
                }
                //if (wuLiaoCoffee.IsWLBol)
                //{
                //saveDeviceMatter save = new saveDeviceMatter();
                //save.matterStatusJson = JsonConvert.SerializeObject(CoffeeMatters.Instance);
                //save.deviceStatusJson = JsonConvert.SerializeObject(deviceStatus.Instance);
                //var saves = JsonConvert.SerializeObject(save);
                //HttpMsg.Instance.saveDeviceMatterMsg(saves);
                //}
            }
            catch (Exception)
            {
                return;
            }
        }
        public void IceMsg(WuLiaoIceSel wuLiaoIce)
        {
            try
            {

                CoffeeMatters.Instance.IceMatter1 = 1;// wuLiaoIce.GT1_Sel_Bol ? 1 : 0;
                CoffeeMatters.Instance.IceMatter2 = 1;// wuLiaoIce.GT2_Sel_Bol ? 1 : 0;
                CoffeeMatters.Instance.IceMatter3 = 1;// wuLiaoIce.GT3_Sel_Bol ? 1 : 0;
                CoffeeMatters.Instance.IceMatter4 = 1;//  wuLiaoIce.GSWL1_Sel_Bol ? 1 : 0;
                CoffeeMatters.Instance.IceMatter5 = 1;//  wuLiaoIce.GSWL2_Sel_Bol ? 1 : 0;
                CoffeeMatters.Instance.IceMatter6 = wuLiaoIce.IsICeMaterial1 ? 1 : 0;
                CoffeeMatters.Instance.IceMatter7 = wuLiaoIce.IsICeMaterial2 ? 1 : 0;
                CoffeeMatters.Instance.IceMatter8 = wuLiaoIce.CupFeed1_Sel_Bol ? 1 : 0;
                CoffeeMatters.Instance.IceMatter9 = wuLiaoIce.RobotWarn ? 1 : 0;
                //CoffeeMatters.Instance.IceMatter10 = wuLiaoIce.CupFeed2_Sel_Bol ? 1 : 0;
                // CoffeeMatters.Instance.IceMatter11 = wuLiaoIce.IsICeMaterial2 ? 1 : 0;
                this.Dispatcher.BeginInvoke(new Action(delegate
                {
                    Ice_AQGS_B.Background = wuLiaoIce.BANNER_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    Ice_AQGS_F.Foreground = wuLiaoIce.BANNER_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    Ice_CCMSDW_B.Background = wuLiaoIce.PushRodUP_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    Ice_CCMSDW_F.Foreground = wuLiaoIce.PushRodUP_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    Ice_CCMXDW_B.Background = wuLiaoIce.PushRodDown_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    Ice_CCMXDW_F.Foreground = wuLiaoIce.PushRodDown_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    Ice_CCJC_B.Background = wuLiaoIce.OutMealCup_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    Ice_CCJC_F.Foreground = wuLiaoIce.OutMealCup_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    Ice_JBCGJC_B.Background = wuLiaoIce.TakeCup_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    Ice_JBCGJC_F.Foreground = wuLiaoIce.TakeCup_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    Ice_JBCGJC2_B.Background = wuLiaoIce.TakeCup2_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    Ice_JBCGJC2_F.Foreground = wuLiaoIce.TakeCup2_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    //BJC12_B.Background = wuLiaoCoffee.CupFeed2_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    //BJC12_F.Foreground = wuLiaoCoffee.CupFeed2_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    Ice_BFK8_B.Background = wuLiaoIce.LBQFK1_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    Ice_BFK8_F.Foreground = wuLiaoIce.LBQFK1_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    Ice_BJC8_B.Background = wuLiaoIce.CupFeed1_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    Ice_BJC8_F.Foreground = wuLiaoIce.CupFeed1_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    Ice2_BJC8_B.Background = wuLiaoIce.CupFeed2_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    Ice2_BJC8_F.Foreground = wuLiaoIce.CupFeed2_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    Ice2_BFK8_B.Background = wuLiaoIce.LBQFK2_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    Ice2_BFK8_F.Foreground = wuLiaoIce.LBQFK2_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    Ice_BQLWLL_B.Background = wuLiaoIce.IsICeMaterial1 ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    Ice_BQLWLL_F.Foreground = wuLiaoIce.IsICeMaterial1 ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    Ice_BQLWLY_B.Background = wuLiaoIce.IsICeMaterial2 ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    Ice_BQLWLY_F.Foreground = wuLiaoIce.IsICeMaterial2 ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    Ice_BQL_B.Background = wuLiaoIce.IceWarn ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    Ice_BQL_F.Foreground = wuLiaoIce.IceWarn ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    Ice_Robot_B.Background = wuLiaoIce.RobotWarn ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    Ice_Robot_F.Foreground = wuLiaoIce.RobotWarn ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    GT1.Text = wuLiaoIce.SugarInit1.ToString();
                    GT2.Text = wuLiaoIce.SugarInit2.ToString();
                    GT3.Text = wuLiaoIce.SugarInit3.ToString();
                    GS1.Text = wuLiaoIce.GSInit1.ToString();
                    GS2.Text = wuLiaoIce.GSInit2.ToString();
                    Ice1.Text = wuLiaoIce.IceIint1.ToString();
                    Ice2.Text = wuLiaoIce.IceIint2.ToString();
                    Ice3.Text = wuLiaoIce.IceIint3.ToString();
                    //  BSTime1.Text = wuLiaoIce.BSInit1.ToString();
                }));
                if (wuLiaoIce.IsWLBol)
                {
                    TestDelegateInvoke testDelegate = new TestDelegateInvoke(DelegateInvokeMethod);
                    testDelegate.BeginInvoke(null, null);
                }
                //if (wul.IsWLBol)
                //{
                //    saveDeviceMatter save = new saveDeviceMatter();
                //    save.matterStatusJson = JsonConvert.SerializeObject(CoffeeMatters.Instance);
                //    save.deviceStatusJson = JsonConvert.SerializeObject(deviceStatus.Instance);
                //    var saves = JsonConvert.SerializeObject(save);
                //    HttpMsg.Instance.saveDeviceMatterMsg(saves);
                //}
            }
            catch (Exception)
            {
                return;
            }
        }

        public delegate void TestDelegateInvoke();

        private void DelegateInvokeMethod()
        {
            try
            {
                Console.WriteLine(CoffeeMatters.Instance.IceMatter8);
                saveDeviceMatter save = new saveDeviceMatter();
                save.matterStatusJson = JsonConvert.SerializeObject(CoffeeMatters.Instance);
                save.deviceStatusJson = JsonConvert.SerializeObject(deviceStatus.Instance);
                var saves = JsonConvert.SerializeObject(save);
                while (true)
                {
                    try
                    {
                        var ddd1 = HttpMsg.Instance.saveDeviceMatterMsg(saves);
                        if (ddd1 != null)
                        {
                            if (ddd1 != "")
                            {
                                var list10 = JsonConvert.DeserializeObject<ListMsg>(ddd1);
                                if (list10 != null)
                                {
                                    if (list10.code == "0" || list10.code == "1")
                                    {
                                        Console.WriteLine(DateTime.Now.ToString() + "  cx25 " + ddd1);
                                        break;
                                    }
                                }
                                Console.WriteLine(DateTime.Now.ToString() + "  cx25 " + ddd1);
                            }
                        }
                        Thread.Sleep(100);
                    }
                    catch (Exception)
                    {
                    }
                }
                //HttpMsg.Instance.saveDeviceMatterMsg(saves);
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        /// 单个按钮改变状态
        /// </summary>
        /// <param name="name"></param>
        /// <param name="tag"></param>
        public void DOSelect(string name, double tag)
        {
            try
            {
                switch (name)
                {
                    case "LB8":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            LB8_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            LB8.Tag = tag;
                            LB8.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                            //ICECC_CMB.SelectedIndex = tag - 1;
                            //ICECC_CMB.Text = tag.ToString();
                        }));
                        break;
                    case "LB12":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            LB12_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            LB12.Tag = tag;
                            LB12.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                            //ICECC_CMB.SelectedIndex = tag - 1;
                            //ICECC_CMB.Text = tag.ToString();
                        }));
                        break;
                    case "CCMSS":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            CCMSS_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            CCMSS.Tag = tag;
                            CCMSS.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "CCMXJ":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            CCMXJ_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            CCMXJ.Tag = tag;
                            CCMXJ.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "LBIce":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            LBIce_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            LBIce.Tag = tag;
                            LBIce.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "GTWL1":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            GTWL1_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            GTWL1.Tag = tag;
                            GTWL1.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "GTWL2":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            GTWL2_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            GTWL2.Tag = tag;
                            GTWL2.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "CCMSSIce":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            CCMSSIce_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            CCMSSIce.Tag = tag;
                            CCMSSIce.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "CCMXJIce":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            CCMXJIce_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            CCMXJIce.Tag = tag;
                            CCMXJIce.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "GJ1":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            GJ1_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            GJ1.Tag = tag;
                            GJ1.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "GJ2":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            GJ2_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            GJ2.Tag = tag;
                            GJ2.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "GJ3":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            GJ3_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            GJ3.Tag = tag;
                            GJ3.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "KW1TGSS":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            KW1TGSS_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            KW1TGSS.Tag = tag;
                            KW1TGSS.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "KW2TGSS":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            KW2TGSS_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            KW2TGSS.Tag = tag;
                            KW2TGSS.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "KW3TGSS":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            KW3TGSS_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            KW3TGSS.Tag = tag;
                            KW3TGSS.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "KW1TGXJ":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            KW1TGXJ_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            KW1TGXJ.Tag = tag;
                            KW1TGXJ.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "KW2TGXJ":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            KW2TGXJ_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            KW2TGXJ.Tag = tag;
                            KW2TGXJ.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "KW3TGXJ":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            KW3TGXJ_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            KW3TGXJ.Tag = tag;
                            KW3TGXJ.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    default:
                        break;
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        /// 给按钮变颜色
        /// </summary>
        /// <param name="btn">要变颜色得按钮</param>
        /// <param name="type">1，正常 2，接通变1 3，不缺料 4，缺料</param>
        /// <param name="img">要变颜色得按钮 开</param>
        ///  <param name="img1">要变颜色得按钮 关</param>
        public void BtnShow(Button btn, int type, Image img, Image img1)
        {
            try
            {
                this.Dispatcher.BeginInvoke(new Action(delegate
                {
                    if (type == 0)//正常状态do
                    {
                        btn.Tag = 0;
                        img.Source = new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                        img1.Source = new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png"));

                    }
                    else if (type == 1)//接通变1do
                    {
                        btn.Tag = 1;
                        img1.Source = new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                        img.Source = new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png"));
                    }
                }));
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        ///   状态  0 关状态  1 开状态 2 已开机 3 上电 4 下电 5 已使能 6 下使能 7 已运行 8 继续运行 9 已报警 10 已暂停  11已停止 ,12 机械臂状态查询
        /// </summary>
        /// <param name="robotName"></param>
        /// <param name="type"> </param>
        public void Robot_CZ(string robotName, int type)
        {
            try
            {
                if (isCoffeeRobot)
                {
                    if (CoffeeSocket != null)
                    {
                        ClientList clientList = new ClientList();
                        MessageClientList coffeelist = MessageClientList.Instance;
                        coffeelist.Name = robotName;
                        coffeelist.type = type;
                        clientList.message = coffeelist;
                        clientList.code = 3;
                        CoffeeSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
                    }
                }
                else
                {
                    MessageBox.Show("Please update later, the program is loading!");
                }
            }
            catch (Exception ex)
            {
                return;
            }
        }
        /// <summary>
        ///   状态  0 关状态  1 开状态 2 已开机 3 上电 4 下电 5 已使能 6 下使能 7 已运行 8 继续运行 9 已报警 10 已暂停  11已停止 ,12 机械臂状态查询
        /// </summary>
        /// <param name="robotName"></param>
        /// <param name="type"> </param>
        public void Robot_CZ_Ice(string robotName, int type)
        {
            try
            {
                if (isIceRobot)
                {
                    if (IceSocket != null)
                    {
                        ClientList clientList = new ClientList();
                        MessageClientList coffeelist = MessageClientList.Instance;
                        coffeelist.Name = robotName;
                        coffeelist.type = type;
                        clientList.message = coffeelist;
                        clientList.code = 3;
                        IceSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
                    }
                }
                else
                {
                    MessageBox.Show("Please update later, the program is loading!");
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        public void RobotSel_L(RobotMsg robotMsg)
        {
            try
            {
                this.Dispatcher.BeginInvoke(new Action(delegate
                {
                    robot_kj_L.Source = robotMsg.Robot_YKJ ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_sd_L.Source = robotMsg.Robot_SD ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_sn_L.Source = robotMsg.Robot_SN ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_yx_L.Source = robotMsg.Robot_YX ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_zt_L.Source = robotMsg.Robot_ZT ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_bj_L.Source = robotMsg.Robot_BJ ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_tz_L.Source = robotMsg.Robot_TZ ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png")); ;
                    RobotYN_L(robotMsg);
                }));
            }
            catch (Exception)
            {
                return;
            }
        }
        public void RobotSel_LN(RobotMsg robotMsg)
        {
            try
            {
                this.Dispatcher.BeginInvoke(new Action(delegate
                {
                    robot_kj_I.Source = robotMsg.Robot_YKJ ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_sd_I.Source = robotMsg.Robot_SD ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_sn_I.Source = robotMsg.Robot_SN ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_yx_I.Source = robotMsg.Robot_YX ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_zt_I.Source = robotMsg.Robot_ZT ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_bj_I.Source = robotMsg.Robot_BJ ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_tz_I.Source = robotMsg.Robot_TZ ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png")); ;
                    RobotYN_N(robotMsg);
                }));
            }
            catch (Exception)
            {
                return;
            }
        }
        public void RobotSel_R(RobotMsg robotMsg)
        {
            try
            {
                this.Dispatcher.BeginInvoke(new Action(delegate
                {
                    robot_kj_R.Source = robotMsg.Robot_YKJ ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_sd_R.Source = robotMsg.Robot_SD ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_sn_R.Source = robotMsg.Robot_SN ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_yx_R.Source = robotMsg.Robot_YX ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_zt_R.Source = robotMsg.Robot_ZT ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_bj_R.Source = robotMsg.Robot_BJ ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_tz_R.Source = robotMsg.Robot_TZ ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png")); ;
                    RobotYN_R(robotMsg);
                }));
            }
            catch (Exception)
            {
                return;
            }
        }
        public void RobotYN_L(RobotMsg robotMsg)
        {
            try
            {
                LTypeKJ_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LTypeBJ_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LOpenBTDY_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LCloseBTDY_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LOpenSSN_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LCloseSSN_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LOpenYXCX_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LCloseTZCX_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LContinueZTCX_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LCloseJXCX_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                L_SD.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_BJ.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_BTSD.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_BTXD.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_SSN.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_XSN.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_YXCX.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_ZTCX.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_TZCX.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_JXCX.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_SD.Tag = "0";
                L_BJ.Tag = "0";
                L_BTSD.Tag = "0";
                L_BTXD.Tag = "0";
                L_SSN.Tag = "0";
                L_XSN.Tag = "0";
                L_YXCX.Tag = "0";
                L_ZTCX.Tag = "0";
                L_TZCX.Tag = "0";
                L_JXCX.Tag = "0";
                if (!robotMsg.Robot_YKJ && !robotMsg.Robot_BJ && !robotMsg.Robot_YX && !robotMsg.Robot_SN && !robotMsg.Robot_ZT && !robotMsg.Robot_SD && !robotMsg.Robot_TZ)
                {
                    LTypeKJ_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    L_SD.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_SD.Tag = "1";
                }
                else if (robotMsg.Robot_YKJ)
                {
                    LOpenBTDY_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    L_BTSD.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_BTSD.Tag = "1";
                }
                else if (robotMsg.Robot_SD)
                {
                    LCloseBTDY_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LOpenSSN_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    L_BTXD.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_SSN.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_BTXD.Tag = "1";
                    L_SSN.Tag = "1";
                }
                else if (robotMsg.Robot_SN)
                {
                    LOpenYXCX_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LCloseSSN_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    L_YXCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_XSN.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_XSN.Tag = "1";
                    L_YXCX.Tag = "1";
                }
                else if (robotMsg.Robot_YX)
                {
                    LCloseTZCX_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LContinueZTCX_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    L_TZCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_ZTCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_ZTCX.Tag = "1";
                    L_TZCX.Tag = "1";
                }
                else if (robotMsg.Robot_TZ)
                {
                    LOpenYXCX_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LCloseSSN_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    L_YXCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_XSN.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_XSN.Tag = "1";
                    L_YXCX.Tag = "1";
                }
                else if (robotMsg.Robot_ZT)
                {
                    LCloseTZCX_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LCloseJXCX_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    L_JXCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_TZCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_JXCX.Tag = "1";
                    L_TZCX.Tag = "1";
                }
                else if (robotMsg.Robot_BJ)
                {
                    LTypeBJ_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    L_BJ.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_BJ.Tag = "1";
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        public void RobotYN_N(RobotMsg robotMsg)
        {
            try
            {
                LTypeKJ_I.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LTypeBJ_I.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LOpenBTDY_I.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LCloseBTDY_I.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LOpenSSN_I.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LCloseSSN_I.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LOpenYXCX_I.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LCloseTZCX_I.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LContinueZTCX_I.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LCloseJXCX_I.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                I_SD.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                I_BJ.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                I_BTSD.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                I_BTXD.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                I_SSN.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                I_XSN.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                I_YXCX.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                I_ZTCX.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                I_TZCX.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                I_JXCX.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                I_SD.Tag = "0";
                I_BJ.Tag = "0";
                I_BTSD.Tag = "0";
                I_BTXD.Tag = "0";
                I_SSN.Tag = "0";
                I_XSN.Tag = "0";
                I_YXCX.Tag = "0";
                I_ZTCX.Tag = "0";
                I_TZCX.Tag = "0";
                I_JXCX.Tag = "0";
                if (!robotMsg.Robot_YKJ && !robotMsg.Robot_BJ && !robotMsg.Robot_YX && !robotMsg.Robot_SN && !robotMsg.Robot_ZT && !robotMsg.Robot_SD && !robotMsg.Robot_TZ)
                {
                    LTypeKJ_I.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    I_SD.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    I_SD.Tag = "1";
                }
                else if (robotMsg.Robot_YKJ)
                {
                    LOpenBTDY_I.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    I_BTSD.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    I_BTSD.Tag = "1";
                }
                else if (robotMsg.Robot_SD)
                {
                    LCloseBTDY_I.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LOpenSSN_I.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    I_BTXD.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    I_SSN.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    I_BTXD.Tag = "1";
                    I_SSN.Tag = "1";
                }
                else if (robotMsg.Robot_SN)
                {
                    LOpenYXCX_I.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LCloseSSN_I.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    I_YXCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    I_XSN.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    I_XSN.Tag = "1";
                    I_YXCX.Tag = "1";
                }
                else if (robotMsg.Robot_YX)
                {
                    LCloseTZCX_I.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LContinueZTCX_I.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    I_TZCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    I_ZTCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    I_ZTCX.Tag = "1";
                    I_TZCX.Tag = "1";
                }
                else if (robotMsg.Robot_TZ)
                {
                    LOpenYXCX_I.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LCloseSSN_I.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    I_YXCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    I_XSN.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    I_XSN.Tag = "1";
                    I_YXCX.Tag = "1";
                }
                else if (robotMsg.Robot_ZT)
                {
                    LCloseTZCX_I.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LCloseJXCX_I.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    I_JXCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    I_TZCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    I_JXCX.Tag = "1";
                    I_TZCX.Tag = "1";
                }
                else if (robotMsg.Robot_BJ)
                {
                    LTypeBJ_I.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    I_BJ.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    I_BJ.Tag = "1";
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        public void RobotYN_R(RobotMsg robotMsg)
        {
            try
            {
                LTypeKJ_R.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LTypeBJ_R.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LOpenBTDY_R.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LCloseBTDY_R.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LOpenSSN_R.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LCloseSSN_R.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LOpenYXCX_R.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LCloseTZCX_R.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LContinueZTCX_R.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LCloseJXCX_R.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                R_SD.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                R_BJ.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                R_BTSD.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                R_BTXD.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                R_SSN.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                R_XSN.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                R_YXCX.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                R_ZTCX.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                R_TZCX.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                R_JXCX.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                R_SD.Tag = "0";
                R_BJ.Tag = "0";
                R_BTSD.Tag = "0";
                R_BTXD.Tag = "0";
                R_SSN.Tag = "0";
                R_XSN.Tag = "0";
                R_YXCX.Tag = "0";
                R_ZTCX.Tag = "0";
                R_TZCX.Tag = "0";
                R_JXCX.Tag = "0";
                if (!robotMsg.Robot_YKJ && !robotMsg.Robot_BJ && !robotMsg.Robot_YX && !robotMsg.Robot_SN && !robotMsg.Robot_ZT && !robotMsg.Robot_SD && !robotMsg.Robot_TZ)
                {
                    LTypeKJ_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    R_SD.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_SD.Tag = "1";
                }
                else if (robotMsg.Robot_YKJ)
                {
                    LOpenBTDY_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    R_BTSD.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_BTSD.Tag = "1";
                }
                else if (robotMsg.Robot_SD)
                {
                    LCloseBTDY_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LOpenSSN_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    R_BTXD.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_SSN.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_BTXD.Tag = "1";
                    R_SSN.Tag = "1";
                }
                else if (robotMsg.Robot_SN)
                {
                    LOpenYXCX_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LCloseSSN_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    R_YXCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_XSN.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_XSN.Tag = "1";
                    R_YXCX.Tag = "1";
                }
                else if (robotMsg.Robot_YX)
                {
                    LCloseTZCX_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LContinueZTCX_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    R_TZCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_ZTCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_ZTCX.Tag = "1";
                    R_TZCX.Tag = "1";
                }
                else if (robotMsg.Robot_TZ)
                {
                    LOpenYXCX_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LCloseSSN_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    R_YXCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_XSN.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_XSN.Tag = "1";
                    R_YXCX.Tag = "1";
                }
                else if (robotMsg.Robot_ZT)
                {
                    LCloseTZCX_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LCloseJXCX_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    R_JXCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_TZCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_JXCX.Tag = "1";
                    R_TZCX.Tag = "1";
                }
                else if (robotMsg.Robot_BJ)
                {
                    LTypeBJ_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    R_BJ.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_BJ.Tag = "1";
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        #endregion
        private void Button_Click(object sender, RoutedEventArgs e)
        {

        }

        private void IMG_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                var name = (sender as Image).Name;
                var tag = (sender as Image).Tag;
                IceSend(name, tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }


        private void exit_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2)
                {
                    MessageBoxResult result = MessageBox.Show("Exit orders will not be made,Do you really want to quit?", "Exit", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
                    if (result == MessageBoxResult.Yes)
                    {
                        foreach (System.Diagnostics.Process thisProc in System.Diagnostics.Process.GetProcesses())
                        {
                            if (thisProc.ProcessName == "NewZealandCoffee")
                            {
                                if (!thisProc.CloseMainWindow())
                                    thisProc.Kill(); //当发送关闭窗口命令无效时强行结束进程     
                            }
                            if (thisProc.ProcessName == "DuBaiCoffee2")
                            {
                                if (!thisProc.CloseMainWindow())
                                    thisProc.Kill(); //当发送关闭窗口命令无效时强行结束进程     
                            }
                            if (thisProc.ProcessName == "MINIGKP")
                            {
                                if (!thisProc.CloseMainWindow())
                                    thisProc.Kill(); //当发送关闭窗口命令无效时强行结束进程     
                            }
                        }
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            System.Windows.Application.Current.Shutdown();
                        }));
                    }
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        private void NaichaRobot_Click(object sender, RoutedEventArgs e)
        {

        }

        private void DDZZ_Click(object sender, RoutedEventArgs e)
        {

        }


        private void IMG1_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                var name = (sender as Image).Name;
                var tag = (sender as Image).Tag;
                CoffeeSend(name, tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }

        private void TTime1_LostFocus(object sender, RoutedEventArgs e)
        {
            try
            {
                var text = (sender as TextBox).Text;
                var name = (sender as TextBox).Name;
                IceSend(name, (double.TryParse(text.ToString(), out double ttime1) ? ttime1 : 1).ToString());
            }
            catch (Exception)
            {
                return;
            }
        }

        private void Test1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                IceSend("GTCS1", (double.TryParse(GT1.ToString(), out double ttime1) ? ttime1 : 1).ToString());
            }
            catch (Exception)
            {
                return;
            }
        }

        private void Test2_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                IceSend("GTCS2", (double.TryParse(GT2.ToString(), out double ttime1) ? ttime1 : 1).ToString());
            }
            catch (Exception)
            {
                return;
            }
        }

        private void Test3_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                IceSend("GTCS3", (double.TryParse(GT3.ToString(), out double ttime1) ? ttime1 : 1).ToString());
            }
            catch (Exception)
            {
                return;
            }
        }

        private void Sest1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                IceSend("GSCS1", (double.TryParse(GS1.ToString(), out double ttime1) ? ttime1 : 1).ToString());
            }
            catch (Exception)
            {
                return;
            }
        }

        private void Sest2_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                IceSend("GSCS2", (double.TryParse(GS2.ToString(), out double ttime1) ? ttime1 : 1).ToString());
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        ///   状态  0 关状态  1 开状态 2 已开机 3 上电 4 下电 5 已使能 6 下使能 7 已运行 8 继续运行 9 已报警 10 已暂停  11已停止 ,12 机械臂状态查询
        /// </summary>
        /// <param name="robotName"></param>
        /// <param name="type"> </param>

        private void L_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                var name = (sender as TextBlock).Name;
                var tag = (sender as TextBlock).Tag;
                var names = name == "L_BJ" ? 9 : name == "L_BTSD" ? 3 : name == "L_BTXD" ? 4 : name == "L_SSN" ? 5 : name == "L_XSN" ? 6 : name == "L_YXCX" ? 7 : name == "L_TZCX" ? 11 : name == "L_ZTCX" ? 10 : name == "L_JXCX" ? 8 : 12;
                if (tag.ToString() == "1")
                {
                    Robot_CZ("Reload_L", names);
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        private void I_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                var name = (sender as TextBlock).Name;
                var tag = (sender as TextBlock).Tag;
                var names = name == "I_BJ" ? 9 : name == "I_BTSD" ? 3 : name == "I_BTXD" ? 4 : name == "I_SSN" ? 5 : name == "I_XSN" ? 6 : name == "I_YXCX" ? 7 : name == "I_TZCX" ? 11 : name == "I_ZTCX" ? 10 : name == "I_JXCX" ? 8 : 12;
                if (tag.ToString() == "1")
                {
                    Robot_CZ_Ice("Reload_I", names);
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        private void R_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                var name = (sender as TextBlock).Name;
                var tag = (sender as TextBlock).Tag;
                var names = name == "R_BJ" ? 9 : name == "R_BTSD" ? 3 : name == "R_BTXD" ? 4 : name == "R_SSN" ? 5 : name == "R_XSN" ? 6 : name == "R_YXCX" ? 7 : name == "R_TZCX" ? 11 : name == "R_ZTCX" ? 10 : name == "R_JXCX" ? 8 : 12;
                if (tag.ToString() == "1")
                {
                    Robot_CZ("Reload_R", names);
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        /// 咖啡机器人
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CoffeeRobot_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                wuliao.Visibility = Visibility.Collapsed;
                Caozuo.Visibility = Visibility.Collapsed;
                CoffeeQuYu.Visibility = Visibility.Visible;
                IceCreamQuYu.Visibility = Visibility.Collapsed;
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        /// 冰淇淋机器人
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void IceCreamRobot_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                wuliao.Visibility = Visibility.Collapsed;
                Caozuo.Visibility = Visibility.Collapsed;
                CoffeeQuYu.Visibility = Visibility.Collapsed;
                IceCreamQuYu.Visibility = Visibility.Visible;
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        /// 物料界面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void material_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                try
                {
                    wuliao.Visibility = Visibility.Visible;
                    Caozuo.Visibility = Visibility.Collapsed;
                    CoffeeQuYu.Visibility = Visibility.Collapsed;
                    IceCreamQuYu.Visibility = Visibility.Collapsed;
                }
                catch (Exception)
                {
                    return;
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        /// 操作界面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Operation_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                wuliao.Visibility = Visibility.Collapsed;
                Caozuo.Visibility = Visibility.Visible;
                CoffeeQuYu.Visibility = Visibility.Collapsed;
                IceCreamQuYu.Visibility = Visibility.Collapsed;
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        /// 切换操作界面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void qiehuan_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (qiehuan.Tag.ToString() == "0")
                {
                    colm1.Visibility = Visibility.Collapsed;
                    colm2.Visibility = Visibility.Visible;
                    Col1.Visibility = Visibility.Collapsed;
                    Col2.Visibility = Visibility.Visible;
                    qiehuan.Tag = "1";
                }
                else
                {
                    colm1.Visibility = Visibility.Visible;
                    colm2.Visibility = Visibility.Collapsed;
                    Col1.Visibility = Visibility.Visible;
                    Col2.Visibility = Visibility.Collapsed;
                    qiehuan.Tag = "0";
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        private void Reload_L_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                Robot_CZ("Reload_L", 12);
            }
            catch (Exception)
            {

                return;
            }

        }

        private void Reload_R_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                Robot_CZ("Reload_R", 12);
            }
            catch (Exception)
            {

                return;
            }
        }

        private void Reload_I_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                Robot_CZ_Ice("Reload_I", 12);
            }
            catch (Exception)
            {

                return;
            }
        }

        private void Ice1_LostFocus(object sender, RoutedEventArgs e)
        {

        }
    }
}
